home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / SAT 2.3.8 / Demos / Collision][ demo ƒ / Collision][.p < prev    next >
Text File  |  1996-05-23  |  2KB  |  65 lines

  1. {******************************}
  2. {********* SAT Collision ][ **********}
  3. {******************************}
  4.  
  5. {A more advanced version of SAT Collision, demonstrating the use of callback routines}
  6. {(hit task) for collision handling. What has happened is that the apples switch between}
  7. {good and bad, and we are not supposed to eat it when it's bad.}
  8.  
  9. program SATcollisionII;
  10.  
  11.     uses
  12. {$ifc UNDEFINED THINK_PASCAL}
  13.         Types, QuickDraw, Menus, Windows, TextEdit, Fonts, Dialogs, Memory, {OSEvents,{}
  14.         Events,
  15. {$endc}
  16.         SAT, sMrEgghead, sApple;
  17.  
  18.     var
  19.         ignoreSp: SpritePtr;
  20.         l: longint;
  21.         ignore: integer;
  22.         p: Point;
  23. begin
  24. {Standard Inits are done by Think Pascal.}
  25. {$ifc UNDEFINED THINK_PASCAL}
  26.     InitGraf(@qd.thePort);
  27.     InitFonts;
  28.     InitWindows;
  29. {InitMenus;}
  30. {TEInit;}
  31.     InitDialogs(nil);
  32.     MaxApplZone;
  33. {$endc}
  34.  
  35. {We configure for kBackwardCollision. We can't use kKindCollision here, since we want "friends"}
  36. {to hit each other as well as "enemies".}
  37.     SATConfigure(true, kVPositionSort, kBackwardCollision, 32);
  38.  
  39.     SATInit(128, 129, 512, 322);
  40.  
  41.     InitMrEgghead;
  42.     InitApple;
  43.  
  44.     GetMouse(p);
  45.     ignoreSp := SATNewSprite(0, p.h, p.v, @SetupMrEgghead);
  46.     ignoreSp := SATNewSprite(0, 0, SATRand(gSAT.offSizeV - 32), @SetupApple);
  47.  
  48.     HideCursor;
  49.  
  50. {Optional init for better sound. Get two channels if possible, since we use fairy long sounds.}
  51.     ignore := SATSoundInitChannels(2);
  52.  
  53.     repeat
  54.         l := TickCount;
  55.         SATRun(true);
  56. {Start a new sprite once in a while.}
  57.         if SATRand(40) = 1 then
  58.             ignoreSp := SATNewSprite(0, 0, SATRand(gSAT.offSizeV - 32), @SetupApple);
  59.         while l > TickCount - 2 do {Maximize speed to 30 fps}
  60.             ;
  61.     until Button;
  62.     ShowCursor;
  63.     FlushEvents(mDownMask, 0); {Flush the mouse click, so we won't click randomly in the Finder!}
  64.     SATSoundShutUp; {Always make sure the sound channel is de-allocated!}
  65. end.